// pages/index/cardCenter/cardCenter.js
var app = getApp(),
  that;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardCenter: [],
    page: 1,
    limit: 10,
    isLoadMore: true,
    isJzz: false,
    isJzwb: false
  },
  onLoad: function(res) {
    that = this
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // this.reLoad();

    that.getCarCenter()
  },
  getCarCenter() {
    app.getData({
      url: app.api.getCika(),
      data: {
        companyId: app.globalData.companyId,
        page: that.data.page,
        rows: that.data.limit
      },
      ok: function(res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            if (that.data.page == 1) {
              that.data.cardCenter = []
            }
            if (that.data.cardCenter.length == res.data.totals) {
              that.setData({
                isLoadMore: false,
                isJzz: true,
              })
            }else if(res.data.list.length < that.data.limit) {
              that.setData({
                cardCenter: that.data.cardCenter.concat(res.data.list),
                isLoadMore: false,
                isJzz:false,
              })
            } else {
              that.setData({
                cardCenter: that.data.cardCenter.concat(res.data.list),
                isLoadMore: true,
                page: that.data.page + 1
              })
            }
          }

        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }
      }
    })
  },
  //小程序触底方法
  onReachBottom: function(res) {
    if (that.data.isLoadMore) {
      that.getCarCenter()
    } else {
      that.setData({
        isJzwb: true,
        isJzz: true
      })
      wx.showToast({
        title: '没有更多数据',
        icon: 'none'
      })
    }
  }

})